<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>会员管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">

    <%@include file="../include/commonFile.jsp" %>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/circle/member/list.do?id=${circle.id}" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <%-- 				<input type="hidden" name="id"  value="${circle.id}"/> --%>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">名称</label>
                                <div class="layui-input-inline">${member}
                                    <input type="text" name="realName" autocomplete="off" class="layui-input"
                                           value="${realName}" placeholder="请输入">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">电话号码</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="mobile" autocomplete="off" class="layui-input"
                                           value="${mobile}" placeholder="请输入">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <label class="search-form-lable">类型</label>
                                <div class="layui-input-inline">
                                    <select name="tagId">
                                        <option value="">全部</option>
                                        <c:forEach var="tag" items="${circleTags}">
                                            <option value="${tag.id}" ${tagId == tag.id ? 'selected="selected"' : ''}>${tag.tagName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">加入时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <div class="cl">
                    <table class="layui-table">
                        <colgroup>
                            <col width="75px">
                            <col width="200px">
                            <col width="130px">
                            <col width="100px">
                            <col width="20%">
                            <col width="150px">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>名称</th>
                            <th>电话号码</th>
                            <th>角色</th>
                            <th>类型</th>
                            <th>加入时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="item" items="${list}" varStatus="st">
                            <tr>
                                <td>${page.limit * (page.page-1) + st.count}</td>
                                <td class="table-member" title="${item.memberName}"  onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${item.memberId}','400px','470px')">
                                    <div class="member-cell">
                                        <div class="member-logo common-img" >
                                            <img src="<c:if test="${item.memberLogo!= null}">${item.memberLogo}?imageMogr2/auto-orient/crop/126x126</c:if>" alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                        </div>
                                        <div class="member-name ellipsis-1"><a class="blue" title="${item.memberName}" href="javascript:void(0);">${item.memberName}</a></div>
                                    </div>
                                </td>
                                <td>
                                    <div>${item.memberMobile}</div>
                                </td>
                                <td>
                                    <div>${item.isAdmin == 1 || item.memberId == circle.createBy ? '管理员':'会员'}</div>
                                </td>
                                <td>
                                    <div>${item.tags}</div>
                                </td>
                                <td>
                                    <div><fmt:formatDate value="${item.updateDate}" pattern="yyyy-MM-dd HH:mm" /></div>
                                </td>
                                <td  class="tb-opts">
                                    <div class="comm-opts">
                                        <a target="_self" class="" href="javascript:openDialog('分配类型','${ctx}/circle/tag/setTag.do?circle=${circle.id}&member=${item.memberId}','400px','300px')">
                                            分配类型
                                        </a>
                                        <c:if test="${item.memberId != circle.createBy}">
                                            <a target="_self" class="" href="${ctx}/circle/topic/form.do?cId=${circle.id}&mId=${item.memberId}">
                                                代发话题
                                            </a>
                                        </c:if>
                                        <c:if test="${(empty item.isAdmin || item.isAdmin == 0) && item.memberId != circle.createBy}">
                                            <a target="_self" class="" href="javascript:setMgr('${item.id}')">
                                                设为管理员
                                            </a>
                                        </c:if>
                                        <c:if test="${item.isAdmin == 1 && item.memberId != circle.createBy}">
                                            <a target="_self" class="" href="javascript:cancelMgr('${item.id}')">
                                                取消管理员
                                            </a>
                                        </c:if>
                                        <a target="_self" class="red" href="javascript:removeMember('${item.id}')">
                                            移除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <c:if test="${page.totalCount == 0}">
                        <div class="f16 tc mt15">还没有会员</div>
                    </c:if>
                </div>
            </div>
            <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">

    showActive('${input.createStart}', '${input.createEnd}', '#timeType');
    $(function () {
        //加载分页
        loadPageNew({elem: 'page_content', totalCount: '${page.totalCount}', limit: '${page.limit}', page: '${page.page}'});
        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });
    })
    function setMgr(id) {
        layer.confirm('确定要设置为管理员么？', {icon: 3, title: '提示'}, function (index) {
            $.post('${ctx}/circle/member/setMgr.do', {id: id}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess('设置成功', function () {
                        location.reload();
                    });
                } else {
                    util.layerMsgError(res.description);
                }
            });
        });
    }

    function cancelMgr(id) {
        layer.confirm('确定要取消管理员么？', {icon: 3, title: '提示'}, function (index) {
            $.post('${ctx}/circle/member/cancelMgr.do', {id: id}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess('取消成功', function () {
                        location.reload();
                    });
                } else {
                    util.layerMsgError('取消失败');
                }
            });
        });
    }
    function removeMember(id) {
        layer.confirm('确定移除该会员么？', {icon: 3, title: '提示'}, function (index) {
            $.post('${ctx}/circle/member/del.do', {id: id}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess('移除成功', function () {
                        location.reload();
                    });
                } else {
                    util.layerMsgError(res.description);
                }
            });
        });
    }
    function openDialog(title, url, width, height, target) {
        layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }

            },
            cancel: function (index) {
            }
        });
    }

</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '圈子管理',
            href: '${ctx}/circle/list.do'
        },{
            name: '${circle.name}'
        },{
            name: '会员管理',
            curr: true
        }],
        info:'<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>',
        btns:[{
            name: '添加会员',
            href: '${ctx}/circle/member/form.do?id=${circle.id}',
            icon: 'add'
        },{
            name: '返回',
            href: '${ctx}/circle/list.do',
            icon: 'back'
        }]
    });
</script>
</body>
</html>